layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //新闻列表
    var tableIns = table.render({
        elem: '#newsList',
        url:"/news/comment?method=getCommentWaitCheck",
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 10000,
        limits : [10,15,20,25,10000],
        id : "newsListTable",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'id', title: 'ID', width:60, align:"center"},
            {field: 'comment', title: '评论内容'},
            {field: 'userName', title: '用户名'},
            {field: 'title', title: '文章标题', width:400},
            {field: 'isShow', title: '是否通过审核', align:'center', templet:'#commentIsCheckBox',width: 150},
        ]],done: function () {
            $("[data-field='id']").css('display','none');
        },
        response: {
            statusCode: 200 //规定成功的状态码，默认：0
        }
    });

    form.on('switch(commentCheck)', function(data){
        //获取新状态值
        var newState = data.elem.checked?1:0;
        console.log(newState)
        //获取所需属性值
        let comment_id = data.elem.attributes['comment_id'].nodeValue;
        console.log(comment_id)
        var params = {}
        params.id = comment_id;
        params.isShow = newState;
        var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            url: API_BASE_URL + '/comment?method=updateComment',
            method: "POST",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: JSON.stringify(params),
            success(res) {
                console.log(res.code)
                if (res.code == 200) {
                    setTimeout(function(){
                        layer.close(index);
                        if(data.elem.checked){
                            layer.msg("审核成功！");
                        }else{
                            layer.msg("取消审核成功！");
                        }
                    },500);
                        //刷新父页面

                }else{
                    layer.msg(res.msg);
                }
            }
        })

    })
})



